Vue.prototype.$http = axios;
axios.defaults.baseURL='http://localhost:80'
Vue.prototype.$fastbaseUrl = "http://115.159.217.249:8888";

function getParams () {
    var search = location.search;	//获取location的search属性，保存在search中
    var params = {};		//创建空对象params
    if (search != "") {		//如果search不是空字符串
        search.slice(1).split("&").forEach(	//?username=zhangdong&pwd=123456;//search去开头?，按&切割为数组，forEach
            function (val) {
                var arr = val.split("=");		//将当前元素值按=切割，保存在arr中
                params[arr[0]] = arr[1];		//向params中添加一个元素,属性名为arr[0],值为arr[1]
            }
        );
    }
    return params;	//返回params
}

//使用axios前置拦截器，让所有的请求都携带uToken
axios.interceptors.request.use(config=>{
    //携带token
    let token =  localStorage.getItem("token");
    if(token){
        config.headers['token']=token;
    }
    return config;
},error => {
    Promise.reject(error);
})

//使用axios后置拦截器，处理没有登录请求
axios.interceptors.response.use(result=>{
    console.debug(result)
    let data = result.data;
    if(!data.success && data.message==="noLogin"){
        //删除token和用户信息
        localStorage.removeItem("token");
        localStorage.removeItem("userLogin");
        location.href = "/login.html";
    }
    return result;
},error => {
    Promise.reject(error);
})


